home *** CD-ROM | disk | FTP | other *** search
/ The Original Shareware 1.1 / The Original Shareware (WeMake CDs)(Volume 1.1)(CDs, Inc)(1993).iso / 22 / printset.zip / PRINTSET.C < prev    next >
C/C++ Source or Header  |  1985-08-13  |  30KB  |  850 lines

  1. /*  PRINTSET.C
  2.  
  3.     Program to allow setup of printer special functions.
  4.  
  5.     Copyright (c) 1985, Hawkeye PC Programmer's SIG
  6.  
  7.  
  8.     Revision History
  9.  
  10.     03/26/85    Version 1.01    Added compiler run-time memory limitations
  11.                                 so the program doesn't overwrite command.com
  12.                                 in high RAM.    Modified by Gordon Waite.
  13.  
  14.                                 Changed exit: if invoked with complete comm
  15.                                 line, no exit messages are printed.  Suggested
  16.                                 by Bob Bryla.  Modified by Gordon Waite.
  17.  
  18.                                 Revised the DELETE key routine during integer
  19.                                 entry.  Changed case where cursor is in last
  20.                                 position.  Modified by Gordon Waite.
  21.  
  22.                                 Changed CHOICES to CHOICE in commands menu.
  23.                                 Modified by Gordon Waite.
  24.  
  25.     07/11/85    Version 1.02    Added color attributes for C/G users.
  26.  
  27.                                 Added the /b option to force monochrome.
  28.  
  29.     07/14/85    Version 1.03    Fixed two printer setups by replacing
  30.                                 upper case IBM's to lower case.  This was
  31.                                 needed to work with the parser forcing
  32.                                 command line arguments to lower case prior
  33.                                 to parsing.  Modified by Gordon Waite.
  34.  
  35.                                 Added a check after the shareware screen is
  36.                                 displayed to look for the user pressing the
  37.                                 ESC key.  If that is done, the program will
  38.                                 now terminate instead of passing on to the
  39.                                 next stage.  Modified by Gordon Waite.
  40.  
  41.     08/08/85    Version 1.04    Fixed problems with the Gemini printer.
  42.  
  43.     08/13/85    Version 1.05    Added oki100-ibm printer setup
  44.  
  45.     This program was compiled using the Computer Innovations C-86 'C'
  46.     compiler, version 2.3, using the small memory model.
  47.  
  48. =======================================================================  */
  49.  
  50.  
  51.  
  52. #define DEBUG   0               /*  set to 0 when done with debugging, else 1 */
  53.  
  54. #include "printset.h"
  55.  
  56. #include "screen1"              /*  shareware & copyright notice              */
  57.  
  58. #define MAXCOMMS  18            /*  current number of possible commands       */
  59. #define MAXCUST   20            /*  20 chars is maximum custom setup string   */
  60.  
  61. struct pstuff {                 /*  definition of a printer data structure    */
  62.     char *pname;
  63.     char *comms[MAXCOMMS];
  64. };
  65.  
  66. #include "printers.c"           /*  actual printer definitions                */
  67.  
  68.  
  69.  
  70. /*  ==================   External Function Declarations ===================== */
  71.  
  72. extern FILE *fopen();
  73. extern int fclose();
  74.  
  75. extern char atcheck();
  76. extern int crt_srcp(), dispmem(), equipmnt(), initcell();
  77. extern int keystrok(), movescrn(), strlen();
  78. extern int beep(), checker(), crt_srcp(), isdigit();
  79. extern int readcls(), readcha(), to24(), writcho();
  80. extern long atoi();
  81. extern char *malloc(), *strcpy();
  82.  
  83.  
  84.  
  85. /*  ==================   Internal Function Declarations  ===================  */
  86.  
  87. int parsecom(), getname(), getcomm(), getout(), setup(), transpos(), usage();
  88. int commhelp(), inint();
  89.  
  90.  
  91.  
  92. /*  =========================   Global Variables  ==========================  */
  93.  
  94. int prntnumb;           /*  number of printer (name) found in command line    */
  95. int prntcomm[MAXCOMMS]; /*  list of number of comm's found in command line    */
  96. int needprnt;           /*  if 1, no printer name was found in command line   */
  97. int needcomm;           /*  if 1, no direct commands were found in comm line  */
  98. char *dolist[MAXCOMMS]; /*  the actual command list to be sent to the printer */
  99. char custlist[MAXCUST]; /*  custom setup array;  filled in by user            */
  100. FILE *p;                /*  pointer to a file                                 */
  101.  
  102. char *commname[] = {    /*  the codes used to identify specific commands      */
  103.                         /*  an array of pointers to character strings         */
  104.     "pi",               /*  pica                                              */
  105.     "el",               /*  elite                                             */
  106.     "co",               /*  compressed                                        */
  107.     "pro",              /*  proportional spacing                              */
  108.     "exon",             /*  expanded print on                                 */
  109.     "exoff",            /*  expanded print off                                */
  110.     "bon",              /*  boldface on                                       */
  111.     "boff",             /*  boldface off                                      */
  112.     "uon",              /*  underline on                                      */
  113.     "uoff",             /*  underline off                                     */
  114.     "norm",             /*  normal character set                              */
  115.     "alt1",             /*  alternate char set #1                             */
  116.     "alt2",             /*  alternate char set #2                             */
  117.     "gr",               /*  graphics char set                                 */
  118.     "ff",               /*  form feed                                         */
  119.     "1-6s",             /*  1/6 inch line spacing                             */
  120.     "1-8s",             /*  1/8 inch line spacing                             */
  121.     "reset",            /*  reset printer                                     */
  122.     0                   /*  Null-terminate the list                           */
  123. };
  124.  
  125. char *commdisp[] = {    /*  the names shown on menus                          */
  126.     "pica",
  127.     "elite",
  128.     "compressed",
  129.     "proportional spacing",
  130.     "expanded print on",
  131.     "expanded print off",
  132.     "boldface on",
  133.     "boldface off",
  134.     "underline on",
  135.     "underline off",
  136.     "normal character set",
  137.     "alternate character set #1",
  138.     "alternate character set #2",
  139.     "graphics character set",
  140.     "form feed",
  141.     "1/6 inch line spacing",
  142.     "1/8 inch line spacing",
  143.     "printer reset",
  144.     0                   /*  Null-terminate the list                           */
  145. };
  146.  
  147. unsigned char *msg1 = "PRINTSET  ver 1.05   (c) 1985, Hawkeye PC User Group, ALL RIGHTS RESERVED";
  148.  
  149.  
  150.  
  151. /*  =======================================================================  */
  152. /*                              M A I N L I N E                              */
  153. /*  =======================================================================  */
  154.  
  155.  
  156. main(argc, argv)
  157. int argc;           /*  number of command line arguments passed in   */
  158. char *argv[];       /*  array of ptrs to the command line arguments  */
  159. {
  160.     int status;     /*  status returned from a function call         */
  161.  
  162.     equipmnt();     /*  find out what equipment we're running on...   */
  163.  
  164.     if (!parsecom( argc, argv )) {  /*  process the command line   */
  165.         /*  if the returned status = 0, something is wrong!  */
  166.         usage();
  167.         exit(1);
  168.     }
  169.  
  170.     if (needprnt OR needcomm)     /*  display the shareware screen  */
  171.         showshar();
  172.  
  173.     if (needprnt)             /*  show a menu of printers              */
  174.         if (!getname())
  175.             exit(1);
  176.  
  177.     if (needcomm)             /*  show a menu of commands              */
  178.         if (!getcomm())
  179.             exit(1);
  180.  
  181.     transpos();   /*  translate the command numbers into commands  */
  182.  
  183.     setup();        /*  actually run out the printer setup codes  */
  184.  
  185.     if (needprnt OR needcomm)   /*  didn't use command line  */
  186.         getout(1);       /*  exit from the program!  */
  187. }
  188.  
  189.  
  190. /*  ==========================  End of Mainline  ==========================  */
  191.  
  192.  
  193.  
  194. /*  =======================================================================  */
  195. /*                            Internal Functions
  196. /*  =======================================================================  */
  197.  
  198.  
  199.  
  200. int usage()     /*  function which shows the user proper invocation of prog  */
  201. {
  202.     int i, j, k;                /*  loop variables  */
  203.     char buff[21];              /*  place to build an output line  */
  204.     char buff2[11];             /*  ditto  */
  205.     char buff3[31];             /*  ditto  */
  206.  
  207.     buff[20] = buff2[10] = buff3[30] = '\0';
  208.  
  209.     puts("");
  210.     puts(msg1);
  211.     puts("");
  212.     puts("usage:  printset [?] [/b] [printer name] [option list] [custom xx xx ... ]\n");
  213.     puts("where available printer names are:");
  214.  
  215.     for (i = 0; printers[i].pname; i += 4) {
  216.         for (j = 0; j < 4 AND printers[i+j].pname; ++j) {
  217.             for (k = 0; k < 20; ++k)
  218.                 if (k < strlen(printers[i+j].pname))
  219.                     buff[k] = printers[i+j].pname[k];
  220.                 else
  221.                     buff[k] = ' ';
  222.             printf("%s", buff);
  223.         }
  224.         if (j != 4)
  225.             break;
  226.     }
  227.  
  228.     printf("\n\nand options are:\n");
  229.  
  230.     for (i = 0; commdisp[i]; i += 2) {
  231.         for (j = 0; j < 2 AND commdisp[i+j]; ++j) {
  232.             for (k = 0; k < 10; ++k)
  233.                 if (k < strlen(commname[i+j]))
  234.                     buff2[k] = commname[i+j][k];
  235.                 else
  236.                     buff2[k] = ' ';
  237.             printf("%s", buff2);
  238.             for (k = 0; k < 30; ++k)
  239.                 if (k < strlen(commdisp[i+j]))
  240.                     buff3[k] = commdisp[i+j][k];
  241.                 else
  242.                     buff3[k] = ' ';
  243.             printf("%s", buff3);
  244.         }
  245.         if (j != 2)
  246.             break;
  247.     }
  248.     printf("\nThe /b option stops color display for monochrome users with color cards.");
  249. }
  250.  
  251.  
  252. /*  .......................................................................  */
  253.  
  254.  
  255. int showshar()      /*  display the shareware notice  */
  256. {
  257.     int action;     /*  the user's keystroke  */
  258.  
  259.     movescrn( screen1, sizeof(screen1) );
  260.     atcheck( &scrn[1][4], 15, 15, 74 );
  261.     atcheck( &scrn[3][9], 15, 15, 69 );
  262.     dispmem( scrn );
  263.     crt_srcp( 25, 0, 0 );       /*  send the cursor off page             */
  264.     action = keystrok();        /*  get any character from the keyboard  */
  265.     if (action EQUALS ESC)
  266.         exit();
  267.     return;
  268. }
  269.  
  270.  
  271. /*  .......................................................................  */
  272.  
  273.  
  274. int getname()   /*  presents a menu of printer names to the user  */
  275. {
  276.     int answer;             /*  stores the user's reponse  */
  277.     int i;                  /*  loop variable  */
  278.     int row, col;           /*  screen coordinates  */
  279.     unsigned char buff[40]; /*  a buffer to build a printer line  */
  280.     int ok;                 /*  is an entry OK?  1 = yes, 0 = no  */
  281.     int retstat, retchar;   /*  used with inint()   */
  282.  
  283. #if DEBUG
  284.     cls();
  285.     printf("Inside GETNAME\n\n");
  286.     keystrok();
  287. #endif
  288.  
  289.     initcell( &scrn[0][0], ' ', 7, 7 );     /*  clear out the screen buff  */
  290.     checker( &scrn[0][0], 15, 15, msg1 );   /*  copyright message  */
  291.     checker( &scrn[2][0], 7, 4, "List of possible printers:");
  292.  
  293.     row = 5;
  294.     col = 5;
  295.  
  296.     for (i = 0; printers[i].pname; ++i, ++row) {   /*  build the names list  */
  297.         if (i != 0 AND i % 15 EQUALS 0) {      /*  new row  */
  298.             row = 5;
  299.             col += 20;
  300.         }
  301.         sprintf(buff, "%2d.  %s", i+1, printers[i].pname);  /*  build line  */
  302.         checker( &scrn[row][col], 15, 15, buff );   /*  update scrn buffer  */
  303.     }
  304.  
  305.     checker( &scrn[22][0], 15, 4,
  306.              "Please enter your choice  [ESC to exit]  ==>" );
  307.  
  308.     ok = 0;
  309.  
  310.     while (!ok) {
  311.         dispmem( scrn );       /*  display the screen  */
  312.         crt_srcp( 22, 46, 0 );
  313.         checker( &scrn[22][46], 7, 7, "  ");
  314.         crt_srcp( 22, 46, 0 );
  315.         answer = inint( 2, "  ", 1, &retstat, &retchar );
  316.  
  317. #if DEBUG
  318.     cls();
  319.     crt_srcp(0,0,0);
  320.     printf("The returned value of answer is %d.\n", answer);
  321.     printf("Values of RETSTAT = %d, RETCHAR = %d\n\n", retstat, retchar);
  322.     printf("I happens to be = %d\n", i);
  323.     keystrok();
  324. #endif
  325.  
  326.         if (retstat EQUALS 1)    /*  ESC was entered  */
  327.             getout(0);
  328.         if (answer < 1 OR answer > i) {
  329.             beep();
  330.         }   
  331.         else {
  332.             ok = 1;
  333.         }
  334.     }
  335.  
  336.     prntnumb = answer - 1;
  337.  
  338.     return(1);  /*  everything is OK  */
  339. }
  340.  
  341.  
  342. /*  .......................................................................  */
  343.  
  344.  
  345. int getcomm()       /*  present a menu of possible printer commands  */
  346. {
  347.     int answer;             /*  stores the user's reponse  */
  348.     int i;                  /*  loop variable  */
  349.     int row;                /*  screen coordinates  */
  350.     unsigned char buff[40]; /*  a buffer to build a printer line  */
  351.     int ok;                 /*  is an entry OK?  1 = yes, 0 = no  */
  352.     int count;              /*  count of entered values  */
  353.     int tcomms[MAXCOMMS];   /*  temp array to hold status of settings  */
  354.     int found;              /*  turned on when bad entry is found in list  */
  355.     int numbcoms;           /*  number of possible commands  */
  356.     int retstat, retchar;   /*  used with inint()   */
  357.  
  358. #if DEBUG
  359.     cls();
  360.     printf("Inside GETCOMM\n\n");
  361.     keystrok();
  362. #endif
  363.  
  364.     for (i = 0; i < MAXCOMMS; ++i)
  365.         tcomms[i] = 0;
  366.  
  367.     initcell( &scrn[0][0], ' ', 7, 7 );     /*  clear out the screen buff  */
  368.     checker( &scrn[0][0], 15, 15, msg1 );   /*  copyright message  */
  369.     checker( &scrn[2][0], 7, 4, "List of possible commands:");
  370.  
  371.     row = 4;
  372.  
  373.     for (i = 0; commname[i]; ++i, ++row) {   /*  build the comm names list  */
  374.         sprintf(buff, "%2d.  %s", i+1, commdisp[i] );  /*  build line  */
  375.         checker( &scrn[row][7], 15, 15, buff );   /*  update scrn buffer  */
  376.     }
  377.     numbcoms = i;
  378.  
  379.     checker( &scrn[23][0], 15, 4,
  380.              "Please enter your choice  ==>" );
  381.  
  382.     commhelp();
  383.  
  384.     count = 0;
  385.     answer = -1;
  386.  
  387.     while (answer != 0 AND count < MAXCOMMS) {  /*  loop til a 0 is entered  */
  388.         ok = 0;
  389.         while (!ok) {        /*  loop until user enters a valid number  */
  390.             dispmem( scrn );       /*  display the screen  */
  391.             crt_srcp( 23, 31, 0 );
  392.             checker( &scrn[23][31], 7, 7, "  " );
  393.             crt_srcp( 23, 31, 0 );
  394.             answer = inint( 2, "  ", 1, &retstat, &retchar );
  395.             if (retstat EQUALS 1)    /*  ESC was entered  */
  396.                 getout(0);
  397.             if (answer < 0 OR answer > numbcoms)
  398.                 beep();
  399.             else
  400.                 ok = 1;
  401.         }
  402.  
  403.         /*  at this point, user has entered a valid number...  */
  404.         /*  process the answer, and if needed, go back for another entry  */
  405.  
  406.         if (answer != 0) {
  407.             if (tcomms[answer-1] EQUALS 1) {
  408.                 /*  if already entered, toggle it back off  */
  409.                 tcomms[answer-1] = 0;
  410.                 found = 0;
  411.                 for (i = 0; i <= count; ++i) {
  412.                     if (found) {
  413.                         prntcomm[i-1] = prntcomm[i];
  414.                     }
  415.                     else {
  416.                         if (prntcomm[i] EQUALS answer-1) {
  417.                             found = 1;
  418.                         }
  419.                     }
  420.                 }
  421.                 --count;    /*  fix the entry count  */
  422.                 checker( &scrn[answer + 3][5], 7, 7, " " );  /*  fix fancy...  */
  423.             }
  424.             else {
  425.                 tcomms[answer-1] = 1;   /*  mark in our possible command list  */
  426.                 prntcomm[count++] = answer - 1;   /*  add command to our list  */
  427.                 checker( &scrn[answer + 3][5], 15, 14, "»" );  /*  get fancy...  */
  428.             }
  429.         }
  430.     }
  431.  
  432.     if (count EQUALS 0) {      /*  user entered no commands...  */
  433.         getout(0);
  434.     }
  435.  
  436.     return(1);  /*  everything is OK  */
  437. }
  438.  
  439.  
  440. /*  .......................................................................  */
  441.  
  442.  
  443. int commhelp()      /*  places additional help text on screen  */
  444. {
  445.     checker( &scrn[4][55],  15, 15, "INSTRUCTIONS");
  446.     atcheck( &scrn[4][55], 112, 112, 12);
  447.  
  448.     checker( &scrn[6][44],  7, 1, "-- Type in option numbers, pressing");
  449.     checker( &scrn[7][44],  7, 1, "   ENTER between each number.");
  450.  
  451.     checker( &scrn[9][44],  7, 1, "-- Enter a zero (0) to complete the");
  452.     checker( &scrn[10][44],  7, 1, "   setup.");
  453.  
  454.     checker( &scrn[12][44], 7, 1, "-- Press the ESC key to cancel the");
  455.     checker( &scrn[13][44], 7, 1, "   setup and exit the program.");
  456.  
  457.     checker( &scrn[15][44], 7, 1, "-- Entering an option a second time");
  458.     checker( &scrn[16][44], 7, 1, "   will cancel that option.");
  459. }
  460.  
  461.  
  462. /*  .......................................................................  */
  463.  
  464.  
  465. /*  PARSECOM.C
  466.  
  467.     This function is used to parse the command line passed into the
  468.     program PRINTSET.  This function must accomplish three things:
  469.  
  470.     1.  If the user enters a printer name on the command line, PARSECOM
  471.         must take the name and check for its validity.  If the printer
  472.         name is valid, the proper printer number is loaded into the
  473.         global variable PRNTNUMB.  If no printer name is given in the
  474.         command line, parsecom must set the global variable NEEDPRNT
  475.         to zero (0) to reflect that condition.  If a valid printer is 
  476.         found in the command line, the global varialbe NEEDPRNT is set
  477.         to zero (0).
  478.  
  479.     2.  If the user enters printer commands on the line, PARSECOM must
  480.         evaluate each printer command to see if it is valid.  If the command
  481.         is valid, it must be added to a list of valid commands.  This list
  482.         is maintained in the global array PRNTCOMMS.  If valid commands
  483.         are found on the command line, the global variable NEEDCOMM is set
  484.         to one (1).  If no valid commands are found, NEEDCOMM is set to 
  485.         zero (0).
  486.  
  487.     3.  If PARSECOM finds invalid information in the command line, the
  488.         function must return a status code of zero (0) to the calling
  489.         program, to indicate that things have not gone as expected.
  490.  
  491. */
  492.  
  493.  
  494. parsecom( argc, argv )
  495. int argc;         /*  count of the arguments passed in the command line  */
  496. char *argv[];     /*  array of pointers to the individual argument strings  */
  497. {
  498.     int i, j, k, l;      /*  loop variables  */
  499.     int ii;              /*  loop variable  */
  500.     int custpt;          /*  index into custom string  */
  501.     int notint;          /*  not an integer in a setup string  */
  502.     int havecust;        /*  if a 1, we have found a custom setup  */
  503.  
  504. #if DEBUG
  505.     for (i = 0; i < argc; ++i)
  506.         printf("Arg in parsecom: %s\n", argv[i] );
  507.     printf("End of args\n\n");
  508.     keystrok();
  509. #endif
  510.  
  511.     havecust = 0;  /*  initialize custom setting flag  */
  512.  
  513.     /*  first check if user want just a black and white display...  */
  514.     for (i = 1; i < argc; ++i) {
  515.         if (argv[i][0] EQUALS '-' OR argv[i][0] EQUALS '/') {
  516.             if (argv[i][1] EQUALS 'b' OR argv[i][1] EQUALS 'B') {
  517.                 --argc;                        /*  get rid of this arg  */
  518.                 for (j = i; j < argc; ++j) {   /*  pack the comm line up  */
  519.                     argv[j] = argv[j + 1];
  520.                 }
  521.                 forcebw = 1;
  522.                 break;      /*  since we found it, don't look any farther  */
  523.             }
  524.         }
  525.     }
  526.  
  527.  
  528.     for (i = 0; i < MAXCOMMS; ++i)    /*  initialize command list    */
  529.         prntcomm[i] = -1;
  530.  
  531.     if (argc EQUALS 1) {        /*  no arguments...  */
  532.         needprnt = 1;
  533.         needcomm = 1;
  534.         return(1);
  535.     }
  536.  
  537.     /*  if the user enters a question mark as the first argument, give
  538.         a display of program usage, and terminate;   printset ?           */
  539.  
  540.     if (argc >= 2 AND argv[1][0] EQUALS '?') {
  541.         usage();
  542.         exit(0);
  543.     }
  544.  
  545.     for (i = 1; i < argc; ++i) {  /*  change all arguments to lower case  */
  546.         lower( argv[i] );
  547.     }
  548.  
  549.     /*  now check for a valid printer name  */
  550.  
  551.     prntnumb = -1;
  552.     for (i = 0; printers[i].pname != NULL; ++i) {
  553.  
  554. #if DEBUG
  555.     printf("Looking at printer name %s, %s\n", printers[i].pname, argv[1]);
  556. #endif
  557.  
  558.         if (strcmp( printers[i].pname, argv[1] ) EQUALS 0) {
  559.             /* have match */
  560.             prntnumb = i;
  561.             break;
  562.         }
  563.     }
  564.     /*  if printers[i].pname != NULL, there was no match, so set NEEDPRNT  */
  565.     needprnt = 0;
  566.     if (prntnumb EQUALS -1)
  567.         needprnt = 1;
  568.  
  569.     /*  if there are more arguments, then a command(s) have been given on the
  570.         command line.  If none, then set the NEEDCOMM global variable  */
  571.  
  572.     needcomm = 0;
  573.     if (argc EQUALS 2 AND needprnt EQUALS 0) {
  574.         needcomm = 1;   /*  need to present the user with command menu  */
  575.         return(1);      /*  since I know that, get out of here, now!    */
  576.     }
  577.  
  578.     /*  now process any remaining arguments;  they must be commands  */
  579.  
  580.     if (prntnumb EQUALS -1)
  581.         i = 1;
  582.     else
  583.         i = 2;
  584.  
  585.     k = 0;
  586.     for (; i < argc; ++i) {  /*  go from 2 to the number of arguments  */
  587.         /*  take this argument, and test it against the names of the possible
  588.             argument codes, set up in COMMNAME[].  */
  589.  
  590.         /*  if argument is found, add it's number to PRNTCOMMS, else
  591.             get out of the function with a status of 0 to indicate an
  592.             unknown command.  */
  593.  
  594.         if (!strcmp( "custom", argv[i] )) {  /*  check for custom setup  */
  595.  
  596.             for (ii = 0; ii < MAXCUST; ++ii)
  597.                 custlist[ii] = '\0';    /*  set custom area to nulls  */
  598.  
  599.             ++i;    /*  point to the argument past CUSTOM  */
  600.             custpt = 0;             /*  index into custlist array  */
  601.             notint = 0;
  602.  
  603.             for (; !notint AND i < argc; ++i) {
  604.  
  605.                 ii = 0;
  606.  
  607.                 for (ii = 0; argv[i][ii]; ++ii)  /*  are chars digits?  */
  608.                     if (!isdigit(argv[i][ii])) {
  609.                         notint = 1;
  610.                     }
  611.  
  612.                 if (!notint) {
  613.                     custlist[custpt++] = (int)(atoi(argv[i]));
  614.                     havecust = 1;
  615.                 }
  616.                 else {
  617.                     --i;
  618.                 }
  619.             }       /*  end of loop looking for integer arguments  */
  620.         }       /*  end of custom processing  */
  621.  
  622.         if (havecust) {
  623.             prntcomm[k++] = 99; /*  will never get this high naturally  */
  624.         }
  625.  
  626.         if (i EQUALS argc)
  627.             break;
  628.  
  629.         for ( j = 0; commname[j]; ++j) {
  630.  
  631. #if DEBUG
  632.         printf("Comparing %s, %s\n", commname[j], argv[i] );
  633. #endif
  634.  
  635.             if (strcmp( commname[j], argv[i] ) EQUALS 0) { /* have match */
  636.                 prntcomm[k++] = j;
  637.                 break;
  638.             }
  639.         }
  640.         prntcomm[k] = -1;
  641.  
  642.         if (!commname[j]) {     /*  found an invalid command...  */
  643.             cls();
  644.             beep();
  645.             printf("Invalid command line argument:\n");
  646.             printf("printset ");
  647.             for (l = 1; l < argc; ++l) {
  648.                 if (l EQUALS i)
  649.                     printf("*** ");
  650.                 printf("%s ", argv[l]);
  651.                 if (l EQUALS i)
  652.                     printf("*** ");
  653.             }
  654.             printf("\n");
  655.             usage();
  656.             exit(1);
  657.         }
  658.     }       /*  end of loop on arguments  */
  659.     
  660.     if (k EQUALS 0)
  661.         needcomm = 1;
  662.  
  663.     /*  if we get this far, things look OK, so let's exit!  */
  664.  
  665. #if DEBUG
  666.     for (i = 0; i < k; ++i)
  667.         printf("PRNTCOMM %d = %d\n", i, prntcomm[i]);
  668. #endif
  669.  
  670.     return(1);      /*  return code 1 means things are fine...  */
  671. }
  672.  
  673.  
  674. /*  .......................................................................  */
  675.  
  676.  
  677. int transpos()      /*  transposes the prntcomm array into the dolist  */
  678. {
  679.     int i;      /*  loop variable  */
  680.  
  681. #if DEBUG
  682.     printf("Inside TRANSPOS\n");
  683.     keystrok();
  684. #endif
  685.  
  686.     for ( i = 0; prntcomm[i] > -1; ++i ) {
  687.         if (prntcomm[i] EQUALS 99)
  688.             dolist[i] = &custlist[0];
  689.         else
  690.             dolist[i] = printers[prntnumb].comms[prntcomm[i]];
  691.     }
  692.     dolist[i] = NULL;
  693.  
  694.     return;
  695. }
  696.  
  697.  
  698. /*  .......................................................................  */
  699.  
  700.  
  701. int setup()         /*  send the printer codes out to the printer  */
  702. {
  703.     int i;
  704.  
  705. #if DEBUG
  706.     printf("Inside SETUP\n");
  707.     keystrok();
  708. #endif
  709.  
  710.     if((p = fopen("prn:", "w")) EQUALS 0) {
  711.         puts("Error when attempting to open the printer file\n\n");
  712.         exit(1);
  713.     }
  714.  
  715.     for ( i = 0; dolist[i]; ++i )       /*  execute the printer commands  */
  716.         fprintf( p, "%s", dolist[i] );
  717.  
  718.     fclose(p);
  719. }
  720.  
  721.  
  722. /*  .......................................................................  */
  723.  
  724.  
  725. int inint(length, def, confirm, retstat, retchar)  /*  input an integer  */
  726. int length;         /*  maximum length of the desired integer              */
  727. char *def;          /*  default entry                                      */
  728. int confirm;        /*  1 = need CR to return, 0 = return when full        */
  729. int *retstat;       /*  return a 0 here normally, or a 1 if user hits ESC  */
  730. int *retchar;       /*  char which caused the return from this entry       */
  731. {
  732.     char *s;                    /* Ptr to the buffer string */
  733.     int i, position;
  734.     int junk, attrib;           /* used with readcha */
  735.     int row, col, start, stop;  /* used with readcls */
  736.     int c;                      /* the character */
  737.  
  738.     readcls(0, &row, &col, &start, &stop);  /* get current cursor position */
  739.     readcha(0, &junk, &attrib);
  740.  
  741.     s = malloc(length+1);                      /* get space for string */
  742.  
  743.     for(i = 0; i < length; ++i)
  744.         s[i] = ' ';                            /* set string to blanks */
  745.     s[length] = '\0';              /* make it a null-terminated string */
  746.  
  747.     if (def) {
  748.         strcpy(s, def);
  749.         checker(&scrn[row][col], attrib, attrib, def);
  750.         dispmem(scrn);
  751.     }
  752.  
  753.     position = 0;
  754.     *retstat = 0;                      /* Initialize the return status */
  755.  
  756.     while (1) {
  757.  
  758.         c = keystrok();         /* Get a character from the user */
  759.  
  760.         switch (c) {
  761.             
  762.  
  763.             case ESC:           /* The user hit the ESC key  */
  764.  
  765.                 *retstat = 1;
  766.                 *retchar = ESC;
  767.                 return(atoi(s));   /*  This may not be any good at all!  */
  768.                 break;
  769.  
  770.             case CR:            /* Return when the CR is pressed */
  771.  
  772.                 *retchar = CR;
  773.                 if ((position != 0) AND (position != length - 1)) {
  774.                     for(i = position; i < length; ++i)
  775.                         s[i] = ' ';   /* set rest of string to blanks */
  776.                     checker(&scrn[row][col], attrib, attrib, s);
  777.                     dispmem(scrn);
  778.                 }
  779.                 return(atoi(s));
  780.                 break;
  781.  
  782.  
  783.             case 8:         /* The Delete Key (Arrow) */
  784.  
  785.                 if (position != 0) {
  786.                     if (position EQUALS length - 1 AND s[position] != ' ') {
  787.                         s[position] = ' ';
  788.                     }
  789.                     else {
  790.                         --position;
  791.                         s[position] = ' ';
  792.                     }
  793.                     checker(&scrn[row][col], attrib, attrib, s);
  794.                     crt_srcp(row, col + position, 0);
  795.                     writcho(0, 32, 1);
  796.                 }
  797.                 else
  798.                     beep();
  799.                 break;
  800.  
  801.  
  802.             default:
  803.  
  804.                 if (isdigit(c)) {                /* number */
  805.                     if(position EQUALS 0) {
  806.                         for (i = 0; i < length; ++i)
  807.                             s[i] = ' ';
  808.                         checker(&scrn[row][col], attrib, attrib, s);
  809.                         dispmem(scrn);
  810.                     }
  811.                     s[position++] = c;
  812.                     writcho(0, c, 1);
  813.                     checker(&scrn[row][col], attrib, attrib, s);
  814.                     if ((position EQUALS length) AND (!confirm))
  815.                         return(atoi(s));  /* return if confirm isn't needed ! */
  816.                     if (position EQUALS length)
  817.                         --position;
  818.                     crt_srcp(row, col + position, 0);
  819.                 }
  820.                 else
  821.                    beep(); /* Send a beep, it wasn't a good number! */
  822.  
  823.         }       /*  end of the case statement  */
  824.     }       /*  end of the while loop  */
  825. }       /*  end of the function  */
  826.  
  827.  
  828. /*  .......................................................................  */
  829.  
  830.  
  831. int getout(done)        /*  exit from the program  */
  832. int done;               /*  if 1, printer was set, if 0, not  */
  833. {
  834.     cls();
  835.     if (done)
  836.         puts("Printer setup is finished.\n\n");
  837.     else
  838.         puts("Printer settings have not been changed.\n\n");
  839.  
  840.     puts("Thanks for using PRINTSET!\n\n");
  841.     exit(0);
  842. }
  843.  
  844.  
  845.  
  846. /*  ==================================================================  */
  847. /*            End of source code for program PRINTSET.C                 */
  848. /*  ==================================================================  */
  849.  
  850.